package cn.zwxky.android.staff.Follow;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.LsfbFragment;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInjectUtils;

import java.util.ArrayList;
import java.util.List;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.Permission;

/**
 * Created by Administrator on 2017/3/29 0029.
 */

public class FollowFragment extends LsfbFragment {

    /**
     * view 对象
     */
    private View view;

    /**
     * activity对象
     */
    private Activity mactivity;

    /**
     * 项目任务按钮
     */
    @ViewInject(R.id.follow_btn1)
    private RelativeLayout follow_btn1;
    /**
     * 领导安排
     */
    @ViewInject(R.id.follow_btn2)
    private RelativeLayout follow_btn2;

    @ViewInject(R.id.follow_text1)
    private TextView follow_text1;

    @ViewInject(R.id.follow_text2)
    private TextView follow_text2;

    /**
     * 用于存储网络数据存储
     */
    private List<Fragment> fragments;

    /**
     * 项目任务
     */
    private Task task;

    /**
     * 领导安排
     */
    private Arrange2 arrange;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_follow, null);
        ViewInjectUtils.inject(this, view);
        LsfbEvent.getInstantiation().register2(this);
        Permission permission=new Permission(mactivity);
        permission.GetMeshPermission();
        permission.GetAddressBookPermission();
        permission.GetLocationPermission2();

        initFragments();
        selectFragment(0);
        return view;
    }

    /**
     * 用于存储activity对象
     *
     * @param activity
     */
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mactivity = activity;
    }


    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.follow_btn1, R.id.follow_btn2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.follow_btn1:
                selectBtn(0);
                break;
            case R.id.follow_btn2:
                selectBtn(1);
                break;
        }
    }

    /**
     * 初始化Fragment
     */
    public void initFragments() {
        fragments = new ArrayList<>();
        task = new Task();
        arrange = new Arrange2();
        fragments.add(task);
        fragments.add(arrange);
        selectBtn(0);
    }

    /**
     * 选择fragment
     *
     * @param position
     */
    public void selectFragment(int position) {
        mactivity.getFragmentManager().beginTransaction().replace(R.id.fragment_layout, fragments.get(position)).commit();
    }

    /**
     * 选择不同的fragment的样式改变
     *
     * @param position
     */
    public void selectBtn(int position) {
        switch (position) {
            case 0:
                follow_btn1.setBackground(getResources().getDrawable(R.drawable.btn_downline));
                follow_text1.setTextColor(getResources().getColor(R.color.theme_color));
                follow_text2.setTextColor(getResources().getColor(R.color.hint_color));
                follow_btn2.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                selectFragment(position);
                break;
            case 1:
                follow_btn1.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                follow_text1.setTextColor(getResources().getColor(R.color.hint_color));
                follow_text2.setTextColor(getResources().getColor(R.color.theme_color));
                follow_btn2.setBackground(getResources().getDrawable(R.drawable.btn_downline));
                selectFragment(position);
                break;
        }

    }

    @Override
    protected void Resume() {

    }

    @Override
    public void onDestroy() {
        LsfbEvent.getInstantiation().unregister2(this);
        super.onDestroy();
    }

    @Override
    public void initData() {
//        initFragments();
//        selectFragment(0);
    }
}
